home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / 386p_200.zip / CHIPS450.ASM < prev    next >
Assembly Source File  |  1995-01-12  |  17KB  |  527 lines

  1. ; XVD DRIVER FOR Chips&Technologies  VGA CHIPSET 82c450 or 82c453
  2. ;
  3. ; Lots of thanks goes to Finn Thoegersen, and all the people
  4. ; that helped compiling the vgadoc vga information files
  5. ; N.B. If you want to make the PS/2 version of this driver look into
  6. ;      XVDMode for more info
  7.  
  8. .386P
  9. code32 segment para public use32
  10.        assume cs:code32,ds:code32
  11.        
  12.                  include xvdriver.inc
  13.                  include head32.inc
  14.                  org 0
  15.                  align byte ; KEEP BYTE ALIGNMENT TO AVOID
  16.                             ; "align distortions"
  17.  
  18. __XVD_SIGNATURE db 'XVD0'
  19.                 ; XGE Video Driver TYPE ZERO, four byte file marker
  20.                 ; use it to see if the binary file is  an XVD driver
  21.                 ; now here comes the driver base relative offsets
  22.                 ; of every function supported
  23. __XVDBiosCheck    dd offset XVDBiosCheck
  24.                 ; Returns carry clear if video bios is present
  25.                 ; sets vram video pages count into driver table
  26.                 ; and available display mode mask
  27.                 ; in: edi= XVD driver table , ebp= driver base offset
  28. __XVDChipSetCheck dd offset XVDChipSetCheck
  29.                 ; Returns carry clear if chipset is present
  30.                 ; sets vram video pages count into driver table
  31.                 ; and availabl;e display mode mask
  32.                 ; in: edi= XVD driver table , ebp= driver base offset
  33.  
  34.                   ; currently BOTH of these must be successful
  35.                   ; to "get safe access" to the graphics extensions.
  36.                   ;
  37.                   ; If __XVDBiosCheck fails you should want the user
  38.                   ; that bios is not recognized but it is possible to
  39.                   ; test for the chipset and then try to set
  40.                   ; the video mode hoping the mode set values
  41.                   ; are not different.
  42.                   ;
  43.                   ; A future XGE release will try to use VESA functions
  44.                   ; to set the video mode if _XXVDBiosCheck fails
  45.                   ; and then if _XVDChipSetCheck is successful
  46.                   ; it will "unlock" the extensions thru direct chipset access.
  47.                   ;
  48.                   ; To use "extended" multi-page mode 13h you only have
  49.                   ; to check for the chipset (the bios entry is the same
  50.                   ; for all boards) but remember to include in the bios check
  51.                   ; the code needed to "unlock" the vga extensions.
  52.                   ;
  53.                   ; both __XVDBiosCheck and __XVDChipSetCheck
  54.                   ; must be called with:
  55.                   ; edi= XVD driver table ptr
  56.                   ; ebp= driver base address
  57.                   ; _XVDVPages,_XVDTotRam,_XVDVModes and _XVDASize
  58.                   ; will be updated to what the driver supports.
  59.  
  60. __XVDMode         dd offset XVDMode
  61.                   ; Set video mode
  62.                   ; eax=requested video mode
  63.                   ; edi= XVD driver table ptr
  64.                   ; ebp= driver base address
  65.                   ; returns carry clear if successful
  66.  
  67.  
  68. __XVDPage         dd offset XVDPage
  69.                   ; Set the current "accessible"  64k video page
  70.                   ; in: eax= video page number
  71.                   ; out: edi= LINEAR address of video page
  72.                   ;           (subtract _Code32Base to this to get
  73.                   ;            the code32 relative offset)
  74.  
  75. __XVDVisible      dd offset XVDVisible
  76.                   ; Set the base page of display buffer visible on screen
  77.                   ; in: eax= video page number
  78.  
  79. __XVDOpen         dd offset unSupported
  80.                   ; Opens the "linear aperture"
  81.                   ; setting to the nearest aperture available on driver table
  82.                   ; (the 386video module must write on _XVDAperture
  83.                   ;  the "first" AVAILABLE PHYSICAL ADDRESS
  84.                   ;  (nor a code32 relative address neither
  85.                   ;   a "virtual memory" linear address, this functions
  86.                   ;   needs a "raw" address).
  87.                   ; edi=driver table, ebp=driver base address
  88.                   ; Returns carry clear if successful
  89.  
  90. __XVDClose        dd offset unSupported
  91.                   ; Closes the "linear aperture"
  92.                   ; edi=driver table  ebp=driver base offset
  93.  
  94. __XVDLineSize     dd offset XVDLineSize
  95.                   ; Set nex scanline width
  96.                   ; in: eax= requested scanline size
  97.                   ;     edi=driver table
  98.                   ;     ebp=driver base address
  99.                   ; out: nearest scanline size set into driver table
  100.                   ;      but _DispX is not modified
  101.                   ;      (this will be up to you)
  102.  
  103. __XVDSet1Pal      dd offset XVDSet1Pal
  104. __XVDGet1Pal      dd offset XVDGet1Pal
  105. __XVDSet256Pal    dd offset XVDSet256Pal
  106.                   ; RGB palette handling functions
  107.                   ; (identical to _Set1Pal,_Get1Pal,_Set256pal)
  108. __XVDCardType     dd offset XVDCardType
  109.                      ; driver-base relative pointer to ASCIIZ string
  110.                      ; max. 30 character long
  111. __XVDProgrammer   dd offset XVDProgrammer
  112.                      ; driver-base relative pointer to ASCIIZ string
  113.                      ; with multiple lines of text,max. 40 char each
  114.                      ; (use the LF char (code 10h) to mark newlines)
  115. __XVDNotes        dd offset XVDNotes
  116.                      ; driver-base relative pointer to ASCIIZ string
  117.                      ; with multiple lines of text,max. 40 char each
  118.                      ; (use the LF char (code 10h) to mark newlines)
  119.                      ; Of notes about the driver usage and supported display
  120.                      ; cards
  121.  
  122. ; video modes
  123. the_mode dw 0003h,0013h,0078h,0079h
  124. xsquar   dd 0000h,32,32,100
  125. ysquar   dd 0000,24,24,100
  126. ; memory size limits
  127. the_mem  db 1,1,4,5
  128. the_dual db 1,2,8,10
  129.  
  130. modefailure:
  131.         popad
  132. unSupported:
  133.         stc
  134.         ret
  135.  
  136. XVDVisible:
  137.         push eax
  138.         push edx
  139.         shl eax,14 ; from 64k count into eax to dword count into ah
  140.         mov dx,3d4h
  141.         mov al,0Ch
  142.         cli
  143.         out dx,ax    ; set high byte of vga screen start offset
  144.         shr eax,8
  145.         mov dx,3d6h
  146.         mov al,0Ch
  147.         out dx,ax    ; set the higher bits
  148.         sti
  149.         pop edx
  150.         pop eax
  151.         ret
  152.  
  153.  
  154. XVDPage: 
  155.          push eax
  156.          push edx
  157.          shl eax,12
  158.          mov dx,3D6h
  159.          mov al,10h
  160.          out dx,ax
  161.          mov edi,0A0000h
  162.          pop edx
  163.          pop eax
  164.          ret
  165.  
  166. XVDLineSize:
  167.         push edx
  168.         cmp eax,(255*8)  ; max 2040 pixels/line
  169.         jb tooscan
  170.         mov eax,(255*8)
  171. tooscan:add eax,7
  172.         shr eax,3 ; scanline is in 8 byte multiples
  173.         mov dx,3d4h
  174.         mov ah,al
  175.         mov al,13h
  176.         out dx,ax
  177.         shr eax,8
  178.         shl eax,3
  179.         mov [edi+_XVDScanLine],eax
  180.         pop edx
  181.         ret
  182.  
  183. XVDBiosCheck:
  184.         pushad
  185.         mov word ptr ds:V86ax,5F00h
  186.         mov al,10h
  187.         call dword ptr ds:_ExecINT
  188.         cmp byte ptr ds:V86al,5Fh
  189.         jne modefailure
  190.         mov ebx,ds:V86ebx
  191.         shr bl,4
  192.         cmp bl,3
  193.         je goodbios
  194.         cmp bl,4
  195.         jne modefailure
  196. goodbios:
  197.         mov cl,bh
  198.         and cl,03h
  199.         mov eax,2  ;
  200.         inc ecx    ;
  201.         shl eax,cl ; get total memory count
  202.         mov [edi+_XVDVPages],eax
  203.         mov ebx,3 ; supports text80x25 and 320x200 as default
  204.         cmp eax,8 ;512K ??? there must be a 16bit internal path
  205.                   ;so there is enough bandwidth for higher video modes
  206.         jnbe rammed
  207.         or bl,0Fh
  208. rammed:
  209.         mov [edi+_XVDVModes],ebx
  210.         popad
  211.         clc
  212.         ret
  213.  
  214. XVDCardType db 'Chips&Tech 450/453 ISA BUS',0
  215.  
  216. XVDChipSetCheck:
  217.         ; Chipset check is performed after the bios check
  218.         ; you should save the "available ram" settings
  219.         ; obtained from XVDBiosCheck
  220.         ; and then check what the chipset check returned
  221.         ; to be sure you are accessing the board the driver has been
  222.         ; designed for.
  223.         pushad
  224.         ; enter ISA BOARD setup mode
  225.         cli
  226.         mov dx,46E8h
  227.         in al,dx
  228.         or al,10h  ; bit4=on
  229.         and al,0F7h ;bit3=off
  230.         out dx,al
  231.         ; check for chipset marker
  232.         mov dx,104h
  233.         in al,dx
  234.         mov ah,al
  235.         ; exit ISA BOARD setup mode
  236.         mov dx,46E8h
  237.         in al,dx
  238.         and al,0EFh ;bit4=off
  239.         or al,008h ;bit3=on
  240.         out dx,al
  241.         sti
  242.         cmp ah,0A5h ; Chips & Tech ?
  243.         jne modefailure
  244.         mov dx,3d6h
  245.         xor al,al
  246.         out dx,al
  247.         inc edx
  248.         in al,dx
  249.         dec edx
  250.         shr al,4
  251.         cmp al,3
  252.         je goodchip
  253.         cmp al,4
  254.         jne modefailure
  255. goodchip:
  256.         ; retry available memory check
  257.         mov al,4
  258.         out dx,al
  259.         inc edx
  260.         in al,dx
  261.         and al,03h
  262.         mov cl,al
  263.         mov eax,2  ;
  264.         inc ecx    ;
  265.         shl eax,cl ; get total memory count
  266.         mov [edi+_XVDTotRam],eax
  267.         mov [edi+_XVDVPages],eax
  268.         mov ebx,3 ; supports text80x25 and 320x200 as default
  269.         cmp eax,8 ;512K ??? there must be a 16bit internal path
  270.                   ;so there is enough bandwidth for higher video modes
  271.         jnbe chrammed
  272.         or bl,0Fh
  273. chrammed:
  274.         mov [edi+_XVDVModes],ebx
  275.         popad
  276.         clc
  277.         ret
  278.  
  279. XVDProgrammer db 'Card:   Programmer',10
  280.               db '82c450  Lorenzo Micheletto',10
  281.               db '82c453  Lorenzo Micheletto',0
  282.  
  283. XVDMode: pushad
  284.          mov word ptr  ds:V86ax,0003h ; text mode
  285.          mov dword ptr [edi+_XVDCMode],0
  286.          or eax,eax
  287.          jz vid_mode
  288.          cmp eax,4 ; only up to 640x480 on my C&T450
  289.                    ; (don't know if it is the bios or other things)
  290.          jnb modefailure  ; mode not supported
  291.  
  292.          mov ebx,[ebp+eax*4+xsquar]        ; set aspect ratio
  293.          mov [edi+_XSquare],ebx            ;
  294.          mov ebx,[ebp+eax*4+ysquar]        ;
  295.          mov [edi+_YSquare],ebx            ;
  296.          mov bx,[ebp+eax*2+the_mode]  ;
  297.          mov ds:V86ax,bx ; set graphic mode
  298.          mov [edi+_XVDCMode],eax
  299.          mov al,10h
  300.          call dword ptr ds:_ExecINT
  301.          mov eax,[edi+_DispX]        ; set new scanline size
  302.          mov [edi+_XVDScanLine],eax  ;
  303.  
  304. ; 94h (R/W):  Setup Control Register for Microchannel boards
  305. ;bit 0-2  Reserved
  306. ;      3  Enables Adapter VGA if set
  307. ;      4  Enters Setup Mode if set
  308. ;    5-7  Reserved
  309. ;Note: This is the same register as 46E8h.
  310. ;
  311. ;100h (R):  Microchannel ID low
  312. ;bit 0-7  Bit 0-7 of Microchannel Card ID
  313. ;
  314. ;101h (R):  Microchannel ID high
  315. ;bit 0-7  Bit 8-15 of Microchannel Card ID
  316. ;
  317. ;102h (R/W):  Global Enable
  318. ;bit   0  VGA is enabled if set.
  319. ;
  320. ;103h (R/W):  Multiple Enable
  321. ;bit 0-3  Multiple VGA Enable
  322. ;      4  Must be 0 for proper operation of 82c455/6/7.
  323. ;      6  Extension registers at 3B6h/7h if set,
  324. ;         3D6h/7h if not.
  325. ;      7  Extension Registers Access Enable.
  326. ;         VGA Extension registers at 3d7h can only be
  327. ;         accessed if this bit is set.
  328. ;Note: This register only available in Setup Mode.
  329. ;
  330. ;104h (R):  Global ID (Setup)
  331. ;bit 0-7  Chip I/D.  0A5h if Chips and Tech Chip set.
  332. ;Note: this register can only be read if the chip is in setup mode (46E8h/94h
  333. ;      bit 4 is set)
  334. ;
  335. ;3C3h (R/W):  Setup Control PS/2
  336. ;bit   0  Enables motherboard VGA if set
  337. ;      4  Enters Setup mode if set
  338. ;
  339. ;
  340. ;46E8h (R/W):  Setup Control PC/AT Register
  341. ;bit 0-2  Reserved
  342. ;      3  Enables Adapter VGA if set
  343. ;      4  Enters Setup Mode if set
  344. ;    5-7  Reserved
  345. ;Note: This is the same register as 94h.
  346.  
  347.          ; N.B. if you look into vgadocXX.zip
  348.          ; (the version i used was vgadoc3.zip uploaded from x2ftp.oulu.fi)
  349.          ; look into the file describing YOUR card to see
  350.          ; what specific SuperVGA ports you need to access to
  351.          ; turn on extended paging and svga extensions
  352.          ; THEN look into vga.txt to get an idea of what "standard" vga
  353.          ; registers may need tweaking for "extended" 320x200 multipage mode
  354.          ; THEN use DEBUG or other debugging tools to watch
  355.          ; what are the video register values in "vga" or "svga" mode
  356.          ; so you can decide what to do.
  357.          cli
  358.          ; enter C&T ISA/AT BOARD setup mode
  359.          mov dx,46E8h
  360.          in al,dx
  361.          or al,10h  ; bit4=on
  362.          and al,0F7h ; bit3=off
  363.          out dx,al
  364.          ; activate extension
  365.          mov dx,103h
  366.          in al,dx
  367.          or al,80h ; bit7=on = extended registers accessible
  368.          and al,0BFh ;bit6= off = extended ports at 3d6h/3d7h
  369.          out dx,al
  370.          ; exit C&T ISA/AT BOARD setup mode
  371.          mov dx,46E8h
  372.          in al,dx
  373.          and al,0EFh ;bit4=off
  374.          or  al,008h ;bit3=on
  375.          out dx,al
  376.          ; set cpu window to 64k (vga/svga)
  377.          mov dx,3CEh
  378.          mov ax,0606h
  379.          out dx,al
  380.          inc edx
  381.          in  al,dx
  382.          or  al,00000100b
  383.          dec edx
  384.          and al,11110111b
  385.          xchg al,ah
  386.          out dx,ax
  387.          ; disable word/dword mode
  388.          mov dx,3d4h
  389.          mov ax,0E317h
  390.          out dx,ax
  391.          mov ax,00014h
  392.          out dx,ax
  393.          ; set single video page mode with extended paging (bit0)
  394.          ; and "fully linear" display ram raster scanning (svga)
  395.          mov dx,3d6h
  396.          mov ax,050Bh
  397.          out dx,ax
  398.          ; allow the CTRC to cross bank boundaries
  399.          mov al,4
  400.          out dx,al
  401.          inc edx
  402.          in al,dx
  403.          or al,24h  ; write buffer on & CRTC can cross banks
  404.          out dx,al
  405.          sti
  406.          ; this release does not allows a "wide" (>2040) scanline
  407.          popad
  408.          clc
  409.          ret
  410.  
  411. vid_mode:
  412.          mov al,10h
  413.          call dword ptr ds:_ExecINT
  414.          popad
  415.          clc
  416.          ret
  417.  
  418. XVDNotes db 'XVD DRIVER FOR C&T 82c450',10
  419.          db 'by Lorenzo Micheletto',10,10
  420.          db 'Should be compatible with',10
  421.          db 'C&T 82c450 cards too.',10,10
  422.          db 'Supports 256 color video modes',10
  423.          db '320x200,640x400,640x450',10
  424.          db 'but needs at least 512k',10
  425.          db 'for the last two',0
  426.  
  427. STATUS          = 03DAh ; status register port
  428.  
  429. IS_HVSYNC       = 01
  430. IS_VSYNC        = 08
  431.  
  432.  
  433. ; palette ports
  434. DACREAD         = 03C7h
  435. DACWRITE        = 03C8h
  436. DACDATA         = 03C9h
  437.  
  438. ;----------------------------------------------------------------------------
  439. ; Set1Palette        al =  palette entry
  440. ;                    edx = bit 0..7   red
  441. ;                          bit 8..15  green
  442. ;                          bit 16..23 blue 
  443. ;                          bit 24..31 not used
  444.                 
  445. XVDSet1Pal:
  446.                 ; al = palette index
  447.                 ; edx = (XBGR)
  448.                 push eax
  449.                 push ebx
  450.                 mov  ebx,edx
  451.                 push edx
  452.                 shr ebx,2   ; cut out lower bits to get VGA resolution
  453.         mov     dx,DACWRITE
  454.                 and ebx,003F3F3Fh ; eliminate garbage bits
  455.         cli
  456.                 out     dx,al  ; index
  457.         inc    dx
  458.                 mov     al,bl
  459.                 out     dx,al  ; Red
  460.                 mov     al,bh
  461.                 shr     ebx,16
  462.                 out     dx,al  ; Green
  463.                 mov     al,bl
  464.                 out     dx,al  ; Blue
  465.         sti
  466.                 pop edx
  467.                 pop ebx
  468.                 pop eax
  469.         ret
  470.                 
  471. XVDGet1Pal:
  472.                 ; al = palette index
  473.                 ; edx = (XBGR)
  474.                 push eax
  475.                 mov ds:V86bl,al
  476.                 xor edx,edx
  477.                 mov word ptr ds:V86ax,1015h
  478.                 mov al,10h
  479.                 call dword ptr ds:_ExecINT
  480.                 mov dl,ds:V86cl
  481.                 shl edx,16
  482.                 mov dh,ds:V86ch
  483.                 mov dl,ds:V86dh
  484.                 shl edx,2
  485.                 pop eax
  486.                 ret
  487.  
  488. XVDSet256Pal:
  489.                 ; esi = palette pointer
  490.                 pushad
  491.                 mov     ecx,256
  492.         mov     dx,STATUS
  493.                 cli
  494. into_vretrace:
  495.         in      al,dx
  496.                 test    al,IS_VSYNC
  497.         jnz     into_vretrace
  498. outof_vretrace:
  499.         in      al,dx
  500.                 test    al,IS_VSYNC
  501.         jz      outof_vretrace
  502.                 ; now a full vretrace interval is available
  503.                  
  504.         mov     dx,DACWRITE
  505.                 xor     eax,eax
  506.         out    dx,al
  507.                 inc     dx  ; move to DACDATA port
  508.              nextp:
  509.                 mov eax,[esi]
  510.                 add esi,4
  511.                 shr eax,2           ; 8bit to 6bit color values
  512.                 and eax,003F3F3Fh   ;
  513.                 out dx,al ; Red
  514.                 mov al,ah
  515.                 out dx,al ; Green
  516.                 shr eax,16
  517.                 out dx,al ; Blue
  518.                 dec ecx
  519.                 jne nextp
  520.                 sti
  521.                 popad
  522.         ret
  523.      
  524. code32  ends
  525.  
  526.     END
  527.